rm update
[EroBeats.git] / Djinn and Tonic - Erobeats / MessageBox.cpp
blob3a4141ca1488256735733823730bb048b1382cbf
1 #include "MessageBox.h"
3 #include "RescourceKeys.h"
4 #include "ScreenNames.h"
6 MessageBox::MessageBox(int* scrn, ResourceMaster* resou, string mainMessage, string subMessage, string yesMessage, string noMessage)
8 screen = scrn;
9 rsc = resou;
11 font = new Fonts(0, rsc);
12 outlineAnimation = new Animation(rsc->gameAnimations.at(WhiteBlueBG));
14 font->loadFont(SDL_Color{ 100,100,100,00 }, yesMessage, 2);
15 textYes = font->getTexture();
16 font->loadFont(SDL_Color{ 100,100,100,00 }, noMessage, 2);
17 textNo = font->getTexture();
18 font->loadFont(SDL_Color{ 100,100,100,00 }, mainMessage, 2);
19 textMessage = font->getTexture();
20 font->loadFont(SDL_Color{ 100,100,100,00 }, subMessage, 2);
21 textSubMessage = font->getTexture();
23 rectMain = {font->prcnt(0.1, 'x'), font->prcnt(0.1, 'y'), font->prcnt(0.50, 'x'), font->prcnt(0.60, 'y')};
24 rectMessage = { font->prcnt(0.15, 'x'), font->prcnt(0.15, 'y'), font->prcnt(0.4, 'x'), font->prcnt(0.2, 'y') };
25 rectSubMessage = { font->prcnt(0.20, 'x'), font->prcnt(0.30, 'y'), font->prcnt(0.3, 'x'), font->prcnt(0.15, 'y') };
26 rectNo = { font->prcnt(0.15, 'x'), font->prcnt(0.5, 'y'), font->prcnt(0.1, 'x'), font->prcnt(0.1, 'y') };
27 rectYes = { font->prcnt(0.30, 'x'), font->prcnt(0.5, 'y'), font->prcnt(0.1, 'x'), font->prcnt(0.1, 'y') };
29 boxLoop();
33 MessageBox::~MessageBox()
37 void MessageBox::boxLoop()
39 chrono::milliseconds ms = chrono::duration_cast<chrono::milliseconds>(
40 chrono::system_clock::now().time_since_epoch());
42 running = true;
43 double FPSDelay = 50;
45 int initial = 0;
46 int expired = 0;
48 while (running) {
49 ms = chrono::duration_cast<chrono::milliseconds>(
50 chrono::system_clock::now().time_since_epoch());
51 initial = ms.count();
53 processInput();
54 update();
55 play();
56 render();
58 while (expired - initial < FPSDelay) {
59 ms = chrono::duration_cast<chrono::milliseconds>(
60 chrono::system_clock::now().time_since_epoch());
61 expired = ms.count();
64 close();
67 void MessageBox::processInput()
69 SDL_Event evnt;
70 while (SDL_PollEvent(&evnt)) {
71 switch (evnt.type) {
72 case SDL_QUIT:
73 running = false;
74 *screen = Quit;
75 break;
76 case SDL_MOUSEMOTION:
77 SDL_GetMouseState(&x, &y);
78 break;
79 case SDL_MOUSEBUTTONDOWN:
80 mouseClicked = true;
81 break;
82 case SDL_MOUSEBUTTONUP:
83 mouseClicked = false;
84 break;
89 void MessageBox::update() {
90 if (x > rectNo.x && x < (rectNo.x + rectNo.w) && y > rectNo.y && y < (rectNo.y + rectNo.h)) {
91 cout << "ovrN\n";
92 hoverNo = true;
94 else if (x > rectYes.x && x < (rectYes.x + rectYes.w) && y > rectYes.y && y < (rectYes.y + rectYes.h)) {
95 cout << "ovrY\n";
96 hoverYes = true;
98 else {
99 hoverNo = false;
100 hoverYes = false;
102 if (!mouseClicked) {
103 //block execution
104 return;
106 else if (hoverNo) {
107 response = false;
108 running = false;
110 else if (hoverYes) {
111 response = true;
112 running = false;
116 void MessageBox::play() {
120 void MessageBox::render() {
122 SDL_RenderCopy(rsc->rendPtr, rsc->gameBG.at(LangBG), NULL, &rectMain);
124 if (hoverNo) {
125 SDL_RenderCopy(rsc->rendPtr, outlineAnimation->itterateAnimation(30), NULL, &rectNo);
127 else if(hoverYes){
128 SDL_RenderCopy(rsc->rendPtr, outlineAnimation->itterateAnimation(30), NULL, &rectYes);
130 SDL_RenderCopy(rsc->rendPtr, textYes, NULL, &rectYes);
131 SDL_RenderCopy(rsc->rendPtr, textNo, NULL, &rectNo);
132 SDL_RenderCopy(rsc->rendPtr, textMessage, NULL, &rectMessage);
133 SDL_RenderCopy(rsc->rendPtr, textSubMessage, NULL, &rectSubMessage);
135 SDL_RenderPresent(rsc->rendPtr);
138 void MessageBox::close() {
139 SDL_DestroyTexture(textYes);
140 SDL_DestroyTexture(textNo);
141 SDL_DestroyTexture(textMessage);
142 SDL_DestroyTexture(textSubMessage);
144 delete font;
145 delete outlineAnimation;
148 bool MessageBox::getResponse() {
149 return response;